package dynamic;

public class HouseRobber {
    public int rob(int[] nums) {
        if (nums.length == 0)
            return 0;
        if (nums.length == 1) {
            return nums[0];
        }
        if (nums.length == 2) {
            return nums[0] > nums[1] ? nums[0] : nums[1];
        }
        int[] sumArray = new int[nums.length];
        sumArray[0] = nums[0];
        sumArray[1] = nums[0] > nums[1] ? nums[0] : nums[1];
        for (int i = 2; i < nums.length; i++) {
            sumArray[i] = sumArray[i - 2] + nums[i] > sumArray[i - 1] ? sumArray[i - 2] + nums[i] : sumArray[i - 1];
        }
        return sumArray[sumArray.length - 1];
    }
}
